﻿using CSharpTestProject.Utils;
using System;
using System.Data;
using System.Windows.Forms;

namespace CSharpTestProject
{
    public partial class ModifyRecord : Form
    {
        private DataRow row;
        public DataRow Row
        {
            set { row = value; }
        }
        public _Sql sql;
        public ModifyRecord()
        {
            InitializeComponent();
        }

        private void ModifyRecord_Load(object sender, EventArgs e)
        {
            textBox1.Text = row[0].ToString();
            textBox2.Text = row[1].ToString();
            textBox3.Text = row[2].ToString();
            textBox5.Text = row[4].ToString();
            if (row[3].ToString() == "是")
            {
                radioButton1.Checked = true;
            } else
            {
                radioButton2.Checked = true;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string id = row[0].ToString();
            string sfqq = radioButton1.Checked ? "是" : "否";
            string bz = textBox5.Text;
            string modify = $"UPDATE dmb SET sfqq='{sfqq}',bz='{bz}' WHERE xh='{id}'";
            bool is_ok = sql.ManageData(modify);
            
            if (is_ok)
            {
                MessageBox.Show("修改成功！");
                Close();
            } else
            {
                MessageBox.Show("修改失败！");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
